package com.book.dao;

import com.book.bean.Book;
import com.book.bean.Borrow;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookMapper {
    @Results({
            @Result(column = "bid", property = "bookId"),
            @Result(column = "title", property = "bookName"),
            @Result(column = "time", property = "time"),
            @Result(column = "name", property = "studentName"),
            @Result(column = "sid", property = "studentId")
    })
    @Select("select * from borrow, book, student where borrow.bid = book.bid and borrow.sid = student.sid")
    List<Borrow> getBorrowList();
    @Delete("delete from borrow where id = #{id}")
    void deleteBorrow(String id);
    @Results({
            @Result(column = "bid", property = "bid"),
            @Result(column = "title", property = "title"),
            @Result(column = "desc", property = "desc"),
            @Result(column = "price", property = "price")
    })
    @Select("SELECT\n" +
            "\tbook.bid,\n" +
            "\ttitle,\n" +
            "\tsid \n" +
            "FROM\n" +
            "\tbook\n" +
            "\tLEFT JOIN borrow ON book.bid = borrow.bid \n" +
            "WHERE\n" +
            "\tsid IS NULL;")
    List<Book> getBookList();

    @Insert("insert into borrow(sid, bid, time) values(#{sid}, #{bid}, NOW())")
    void addBorrow(@Param("sid") int sid, @Param("bid") int bid);

    @Select("SELECT * FROM book")
    List<Book> getBook();

    @Delete("delete from book where bid = #{bid}")
    void deleteBook(int bid);

    @Insert("insert into book(title, `desc`, price) values(#{title}, #{desc}, #{price})")
    void addBook(@Param("title") String title,@Param("desc") String desc,@Param("price") double price);
}
